<template>
  <div class="login">
    <!-- <van-nav-bar
      left-text="返回首页"
      left-arrow
      @click-left="onClickLeft"
    /> -->
    <van-image :src="url" fit="cover" width="70%" height="100%" />
    <h1>{{ msg }}</h1>
    <van-form @submit="onSubmit">
      <van-field
        v-model="accountNumber"
        name="accountNumber"
        label="用户名"
        placeholder="用户名"
        clearable
      />
      <van-field
        v-model="password"
        type="password"
        name="password"
        label="密码"
        placeholder="密码"
        clearable
      />
      <div style="margin: 16px;">
        <van-button round block type="info" native-type="submit">提交</van-button>
      </div>
    </van-form>
    <!-- <van-button class="btn1" round type="info" @click="registBtn">注册</van-button> -->
  </div>
</template>

<script>
// import { login } from '../api/user'
export default {
  name: 'Login',
  data() {
    return {
      msg: '欢迎使用家庭管理',
      accountNumber: localStorage.getItem('accountNumber') ? localStorage.getItem('accountNumber') : '',
      password: localStorage.getItem('password') ? localStorage.getItem('password') : '',
      data: {},
      url: require('../assets/logo.png')
    }
  },
  methods: {
    registBtn() {
      console.log('注册')
      // 路由跳转
      this.$router.push({ path: '/regist' })
    },
    onClickLeft() {
      this.$router.go(-1)
    },
    async onSubmit(values) {
      console.log('submit', values)
      // 参数
      const params = {
        password: values.password,
        accountNumber: values.accountNumber
      }
      // vuex
      await this.$store.dispatch('user/login', params)
      this.$router.push({ path: '/home/index' })
    }
  }
}

</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.login {
  margin-top: 60px;
}
.btn1 {
  margin-top: 30px;
}
</style>
